<template>
  <div>
    <!--表格-->
    <el-table border
      :data="tableData"
      style="width: 100%"
      :row-class-name="tableRowClassName">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话"
        width="180">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="180">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
      align="right"
      big
      layout="prev, pager, next"
      :total="totals"
      :page-size="pageSize"
      :current-page="currentPage"
      @current-change="gotoPage">
    </el-pagination>
  </div>
</template>


<script>
import axios from "axios";
export default {

  name: 'Hello',

  data () {
    return {
      tableData: [],
      totals:200,
      pageSize:5,
      currentPage:1
    }
  },
  methods: {
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row';
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
    gotoPage(curr){
      // console.log(curr)
      this.currentPage = curr;
      this.findPage();
    },
    /*监听到每一次的点击事件都需要重新发送请求，抽取为一个方法*/
    findPage(){
      let para = {"currentPage":this.currentPage,"pageSize":this.pageSize}
        axios.post("/user/list",para)
          .then(resoult=>{
              this.tableData = resoult.data.rows;
              this.totals = resoult.data.totals;
          })
          .catch(rusoult=>{
              alert("此网络不通！")
          })
    },
  },
  /*钩子函数，在第一次的时候初始化页面列表 ,请求接口*/
  mounted() {
    this.findPage();
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>
